package com.thinker.loan.consumer.service.strategy;

import com.thinker.loan.consumer.model.LoanApplicationRequest;
import com.thinker.loan.consumer.enumeration.LoanStatus;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

@Component
@ConditionalOnProperty(name = "loan.strategy", havingValue = "auto", matchIfMissing = true)
public class AutoApprovalStrategy implements ApprovalStrategy {
    @Override
    public void evaluate(LoanApplicationRequest request) {
        if (request.getCreditScore() >= 700) {
            request.setStatus(LoanStatus.APPROVED);
        } else if (request.getCreditScore() >= 500) {
            request.setStatus(LoanStatus.MANUAL_REVIEWING);
            request.setRejectReason("需要人工审核");
            // TODO 同时将数据投放至 Kafka，供人工审核服务消费
        } else {
            request.setStatus(LoanStatus.REJECTED);
            request.setRejectReason("信用评分不足");
        }
    }
}
